#include "clientMessage.h"
#include "clientInfo.h"
#include "clientConnect.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
int main(int argc, char *argv[]){
		unsigned short port=4000;
		if(argc==2)
			port=atoi(argv[1]);
		int fd=connect2Server("127.0.0.1",port);
		if(fd<0)
			perror("open");
		init_clientMessage(fd);
		pthread_t reader_tid;
		if(pthread_create(&reader_tid,NULL,receiver,(void*)fd)!=0){
			perror("pthread_create");
			exit(1);
		}
		printf("start\n");
		enterUser("test1");
		printf("enterUser\n");
		printf("%s %s\n",myUserInfo.name,myRoomInfo.name);
		printf("1. makeRoom 2.joinRoom\n");
		int s;
		scanf("%d",&s);
		if(s==1){
			printf("roomName?\n");
			char a[100];
			scanf("%s",a);
			makeRoom(a);
			printf("makes room's Info : %d %s",
					myRoomInfo.roomID,myRoomInfo.name);

		}
		else{
			printf("roomId?\n");
			int b;
			scanf("%d",&b);
			joinRoom(b);
			printf("join room's info : %d %s",
					myRoomInfo.roomID, myRoomInfo.name);
		}
		while(1){
			char chat[100];
			scanf("%100s",chat);
			sendChat(chat,myRoomInfo.roomID);
		}
		close(fd);	
		exit(0);



}
